package com.ruoyi.cderp.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cderp.domain.SettleCheckSheet;
import com.ruoyi.cderp.service.ISettleCheckSheetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商对账单Controller
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/SettleCheckSheet")
public class SettleCheckSheetController extends BaseController
{
    @Autowired
    private ISettleCheckSheetService settleCheckSheetService;

    /**
     * 新增时查询关于客户的全部类型单据
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:query')")
    @GetMapping("/query")
    public AjaxResult getInfoList(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
            @RequestParam String supplierId
    )
    {
        return success(settleCheckSheetService.selectFeeSheetCheckDetailList(startDate,endDate,supplierId));
    }

    /**
     * 查询供应商对账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:list')")
    @GetMapping("/list")
    public TableDataInfo list(SettleCheckSheet settleCheckSheet)
    {
        startPage();
        List<SettleCheckSheet> list = settleCheckSheetService.selectSettleCheckSheetList(settleCheckSheet);
        return getDataTable(list);
    }

    /**
     * 导出供应商对账单列表
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:export')")
    @Log(title = "供应商对账单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SettleCheckSheet settleCheckSheet)
    {
        List<SettleCheckSheet> list = settleCheckSheetService.selectSettleCheckSheetList(settleCheckSheet);
        ExcelUtil<SettleCheckSheet> util = new ExcelUtil<SettleCheckSheet>(SettleCheckSheet.class);
        util.exportExcel(response, list, "供应商对账单数据");
    }

    /**
     * 获取供应商对账单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(settleCheckSheetService.selectSettleCheckSheetById(id));
    }

    /**
     * 新增供应商对账单
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:add')")
    @Log(title = "供应商对账单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SettleCheckSheet settleCheckSheet)
    {
        return toAjax(settleCheckSheetService.insertSettleCheckSheet(settleCheckSheet));
    }

    /**
     * 修改供应商对账单
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:edit')")
    @Log(title = "供应商对账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SettleCheckSheet settleCheckSheet)
    {
        return toAjax(settleCheckSheetService.updateSettleCheckSheet(settleCheckSheet));
    }

    /**
     * 删除供应商对账单
     */
    @PreAuthorize("@ss.hasPermi('system:SettleCheckSheet:remove')")
    @Log(title = "供应商对账单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(settleCheckSheetService.deleteSettleCheckSheetByIds(ids));
    }
}
